﻿using FytSoa.Common.Utils;
using FytSoa.Domain.Core.Cache;
using FytSoa.Domain.Core.Result;
using FytSoa.Domain.Sys;
using FytSoa.Sugar;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FytSoa.Application.Sys
{
    [ApiExplorerSettings(GroupName = "v1")]
    public class SysSafetyService : ISysSafetyService
    {
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ApiResult<SafetySetting> Get()
        {
            var model = new SafetySetting();
            var redisStr = RedisService.cli.Get(KeyUtils.SYSTEMSAFETY);
            if (!string.IsNullOrEmpty(redisStr))
            {
                model = JsonConvert.DeserializeObject<SafetySetting>(redisStr);
            }
            return JResult<SafetySetting>.Success(model);
        }
        
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ApiResult<bool> Add(SafetySetting model)
        {
            RedisService.cli.Set(KeyUtils.SYSTEMSAFETY, JsonConvert.SerializeObject(model));
            return JResult<bool>.Success();
        }
    }
}
